package base;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/*
 *      约瑟夫环
 *    starNumber:开始位置
 * 
 * 
 * */

public class Joseph_ring {

	public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
		System.out.println("输入您想要的输入的个数：");
		int number =sc.nextInt();
		System.out.println("输入您制定的规则：");
		int rule= sc.nextInt();
		System.out.println("输入您想从哪开始数数：");
		int starNumber =sc.nextInt();
		getLastNumber(number,rule,starNumber);
		
	}
	
	public static void getLastNumber(int number, int rule, int starNumber) {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < number; i++) {
			list.add(i);
		}
		while (list.size() > 0) {
			starNumber += rule;
			starNumber = starNumber % list.size() - 1;
			if (starNumber < 0) {
				System.out.println(list.get(list.size() - 1));
				list.remove(list.size() - 1);
				starNumber = 0;
			} else {
				System.out.println(list.get(starNumber));
				list.remove(starNumber);
			}

		}
	}

}
